// move(元素，{
// 左右：移动的距离
// }，回调函数)
function move(ele, obj,cb) {
  clearInterval(ele.t)
  ele.t = setInterval(function () {
    let state = true
    for (let key in obj) {
      let now = parseInt(getStyle(ele, key))
      let speed = (obj[key] - now) / 10;
      speed = speed < 0 ? Math.floor(speed) : Math.ceil(speed);
      ele.style[key] = now + speed + 'px';
      if(obj[key] !== now)state = false;
    }
    if(state){
      clearInterval(ele.t)
      cb && cb();
    }
  }, 30)
}
function getStyle(ele, attr) {
  return ele.currentStyle ? ele.currentStyle[attr] : getComputedStyle(ele)[attr]
}
export { move };